package com.currentbp.myMoney;

import com.currentbp.util.all.MoneyUtil;
import org.junit.Test;

/**
 * @author baopan
 * @createTime 1/26/2023 1:43 PM
 */
public class MyInterest {
    @Test
    public void trueInterest() {
        //从20年开始
        int[] years = new int[]{20, 21, 22, 23, 24};
        float[] interest = new float[]{-0.1457f, 0.6024f, 0.1577f, -0.1345f, 0.0627f};//真实的炒股收益
        float[] bases = new float[]{6505, 4500, 20000, 10000, 10000};//真实的炒股本金投入金额
        double result = 0;
        int newScale = 2;
        double input = 0;
        double beforeSum = 0;
        double yearInput = 0;
        double bankSum3 = 0;
        double bankSum4 = 0;
        double bankSum5 = 0;
        double bankSum10 = 0;
        System.out.printf("%9s%9s%9s%9s%9s%9s%9s%9s%9s%9s%n", "year", "总投入", "年前资产", "年尾资产", "今年收益", "今年投入",
                "银行类比(3%)", "银行类比(4%)", "银行类比(5%)", "银行类比(10%)");
        for (int i = 0; i < years.length; i++) {
            double currentMoney = MoneyUtil.add(result, bases[i]);
            double interestMoney = MoneyUtil.multiply(currentMoney, interest[i], newScale);
            result = MoneyUtil.add(currentMoney, interestMoney);
            yearInput = MoneyUtil.add(beforeSum, bases[i]);
            input += bases[i];
            beforeSum = result;
            //银行的模拟数据
            bankSum3 = MoneyUtil.multiply(MoneyUtil.add(bankSum3, bases[i]), 1.0300f, newScale);
            bankSum4 = MoneyUtil.multiply(MoneyUtil.add(bankSum4, bases[i]), 1.0400f, newScale);
            bankSum5 = MoneyUtil.multiply(MoneyUtil.add(bankSum5, bases[i]), 1.0500f, newScale);
            bankSum10 = MoneyUtil.multiply(MoneyUtil.add(bankSum10, bases[i]), 1.1000f, newScale);
            String format = String.format("%9s  %9s  %9s   %9s  %9s  %9s  %9s  %9s  %9s  %9s",
                    years[i], input, yearInput, result, interestMoney,
                    bases[i], bankSum3, bankSum4, bankSum5, bankSum10);
            System.out.println(format);
        }

    }
}
